package start.doubudouyin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import start.doubudouyin.entity.Usersmessage;
import start.doubudouyin.mapper.FollowMapper;
import start.doubudouyin.mapper.UsersmessageMapper;
import start.doubudouyin.service.UsersmessageService;
import java.util.Date;
import java.util.List;

@Service
public class UsersmessageServiceImpl extends ServiceImpl<UsersmessageMapper, Usersmessage>
        implements UsersmessageService {

    @Resource
    private UsersmessageMapper usersmessageMapper;
    @Resource
    private FollowMapper followMapper;

    @Override
    public boolean insertUsersMessage(Usersmessage usersmessage) {
        usersmessage.setSendTime(new Date());
        if (usersmessageMapper.insertUsersMessage(usersmessage) == 1) {
            followMapper.updatechat(usersmessage.getSenderId(), usersmessage.getReceiverId());
            return true;
        }
        return false;
    }

    @Override
    public List<Usersmessage> getChatHistory(String senderId, String receiverId) {
        return usersmessageMapper.getChatHistory(senderId, receiverId);
    }
}